<?php
   $word=htmlspecialchars(trim(addslashes(escapeshellcmd($_POST['search'])))); //Inicialise the variables
   if($_POST['submit']==''){
    $search = "SELECT * FROM articles WHERE article_name LIKE '%$word%'"; //Selecting the information from the database
	$search_query = mysql_query($search); 
    
    if(mysql_num_rows($search_query)==0){
       if(empty($word)){
		     echo "<p style='margin-left: 10px; color: #B20000'>Моля, въведете текст в търсачката!</p>"; //Checking if there is an empty text
	   } else {
		  echo '<table border="0" style="margin-left: 25px; width: 92%; border: 1px solid #B20000">';
	      echo '<tr><td><p style="margin-left: 10px;">Търсене за: <b>'.$word.'</b></p></td></tr>'; //Echo the result
	   } 
	   echo '<tr><td><p style="margin-left: 10px; color: #B20000; font-weight: bold;">Не бяха намерени резултати!</p></td></tr>';
	   echo '</table>';
    }
    else {
	   if(strlen($word)>=4){
	     echo '<table border="0" style="margin-left: 25px; width: 92%;">'; //Echo the result
	     while($row=mysql_fetch_assoc($search_query)){
		   echo '<tr><td><a href="../tutorials/see_articles.php?name='.$row['to_tutorial'].'&amp;module='.$row['place'].'&amp;id='.$row['article_id'].'" class="f">'.$row['article_name'].'</a></td></tr>'; //Echo the article_name
		   echo '<tr><td><p>Дата на добавяне: <span style="color: #3171a0;">'.date('d-m-Y', $row[date_added]).'</span></p></td></tr>'; //Echo the date
		   echo '<tr><td><hr /></td></tr>';
	     }
	     echo '</table>';
       }
	   else {
	     //Echo the information if there is no article or if we have entered falsch word
	     echo "<p style='margin-left: 10px; color: #B20000;'>Моля, въведете текст в търсачката, по-дълъг от 4 символа!</p>";
	     echo '<p style="margin-left: 10px; color: #B20000; font-weight: bold;">Не бяха намерени резултати!</p>';
       }
    }    
   } else {
      echo '';     
   }
?>